package com.atguigu.eduservice.controller;


import com.aiguigu.commonutils.R;
import com.atguigu.eduservice.entity.dto.subject.TreeOneSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author Y丶HS练习谷粒商城
 * @since 2022-09-23
 */
@Api("课程分类标题")
@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {

    @Resource
    private EduSubjectService subjectService;

    @ApiOperation("Excel数据导入")
    @PostMapping("/saveSubject")
    public R saveSubject(
            @ApiParam("Excel文件")
                    MultipartFile file
    ) {
        subjectService.saveSubject(file, subjectService);
        return R.ok();
    }

    @ApiOperation("课程分类列表---树形")
    @GetMapping("/getTreeEntity")
    public R getTreeEntity() {
        List<TreeOneSubject> subjects = subjectService.getTreeEntity();
        return R.ok().data("info", subjects);
    }

}

